import django.utils.timezone as timezone
from django.db import models


# 总时间基类
class FullAtBaseModel(models.Model):
    createdAt = models.DateTimeField('创建时间', default=timezone.now, editable=False)
    updatedAt = models.DateTimeField('修改时间', auto_now=True)
    deletedAt = models.DateTimeField('删除时间', null=True, default=None, blank=True, editable=False)
    isDelete = models.BooleanField('是否删除', default=False, blank=True, editable=False)

    def delete(self, using=None, keep_parents=False):
        self.deletedAt = timezone.now()
        self.isDelete = True
        self.save()

    class Meta:
        abstract = True


# 创建和修改时间基类
class CreateAndUpdateAtBaseModel(models.Model):
    createdAt = models.DateTimeField('创建时间', default=timezone.now, editable=False)
    updatedAt = models.DateTimeField('修改时间', auto_now=True)

    class Meta:
        abstract = True